package cn.star.jots.user.controller;

import cn.star.jots.base.response.JsonResult;
import cn.star.jots.user.pojo.dto.UserLoginParam;
import cn.star.jots.user.pojo.vo.UserVO;
import cn.star.jots.user.service.UserLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/v1/userLogin")
@Api(tags = "用户登录管理")
@Slf4j
public class UserLoginController {

    @Autowired
    UserLoginService userLoginService;

    @PostMapping("/login")
    @ApiOperation(value = "用户登录")
    public JsonResult login(UserLoginParam userLoginParam) {
        log.info("用户登录:userLoginParam={}", userLoginParam);
        UserVO userVO = userLoginService.login(userLoginParam);
        return JsonResult.ok(userVO);
    }

    @PostMapping("/backup")
    @ApiOperation(value = "备用登录")
    public JsonResult backup(UserLoginParam userLoginParam) {
        log.info("备用登录:userLoginParam={}", userLoginParam);
        UserVO userVO = userLoginService.backup(userLoginParam);
        return JsonResult.ok(userVO);
    }
}

